package cn.source.authorizaton.service.impl;

import java.util.List;

import cn.source.common.exception.CustomException;
import cn.source.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.source.authorizaton.mapper.AuthorizedDeviceMapper;
import cn.source.authorizaton.domain.AuthorizedDevice;
import cn.source.authorizaton.service.IAuthorizedDeviceService;

/**
 * authorizatonService业务层处理
 * 
 * @author sourcebyte.vip
 * @date 2025-05-31
 */
@Service
public class AuthorizedDeviceServiceImpl implements IAuthorizedDeviceService 
{
    @Autowired
    private AuthorizedDeviceMapper authorizedDeviceMapper;

    /**
     * 查询authorizaton
     * 
     * @param authorizerId authorizaton主键
     * @return authorizaton
     */
    @Override
    public AuthorizedDevice selectAuthorizedDeviceByAuthorizerId(Long authorizerId)
    {
        return authorizedDeviceMapper.selectAuthorizedDeviceByAuthorizerId(authorizerId);
    }

    /**
     * 查询authorizaton列表
     * 
     * @param authorizedDevice authorizaton
     * @return authorizaton
     */
    @Override
    public List<AuthorizedDevice> selectAuthorizedDeviceList(AuthorizedDevice authorizedDevice)
    {
        authorizedDevice.setAuthorizerId(SecurityUtils.getUserId());
        return authorizedDeviceMapper.selectAuthorizedDeviceList(authorizedDevice);
    }

    /**
     * 新增authorizaton
     * 
     * @param authorizedDevice authorizaton
     * @return 结果
     */
    @Override
    public int insertAuthorizedDevice(List<AuthorizedDevice> authorizedDevice)
    {
        int rows = 0;
        try {
            rows = authorizedDeviceMapper.insertAuthorizedDevice(authorizedDevice);
        }catch (Exception e){
            throw new CustomException("设备已授权，请勿重复授权");
        }
        return rows;
    }

    /**
     * 修改authorizaton
     * 
     * @param authorizedDevice authorizaton
     * @return 结果
     */
    @Override
    public int updateAuthorizedDevice(AuthorizedDevice authorizedDevice)
    {
        return authorizedDeviceMapper.updateAuthorizedDevice(authorizedDevice);
    }

    /**
     * 批量删除authorizaton
     * 
     * @param authorizerIds 需要删除的authorizaton主键
     * @return 结果
     */
    @Override
    public int deleteAuthorizedDeviceByAuthorizerIds(Long[] authorizerIds)
    {
        return authorizedDeviceMapper.deleteAuthorizedDeviceByAuthorizerIds(authorizerIds);
    }

    /**
     * 删除authorizaton信息
     * 
     * @param authorizerId authorizaton主键
     * @return 结果
     */
    @Override
    public int deleteAuthorizedDeviceByAuthorizerId(AuthorizedDevice authorizedDevice)
    {
        return authorizedDeviceMapper.deleteAuthorizedDeviceByAuthorizerId(authorizedDevice);
    }
}
